import "package:flutter/material.dart";

class WrapItem extends StatelessWidget {
  final int span;
  final Widget child;

  const WrapItem({super.key, this.span = 6, required this.child})
      : assert(span >= 0 && span <= 12);

  @override
  Widget build(BuildContext context) {
    double cols = 12 / span;
    double spacing =
        context.findAncestorWidgetOfExactType<Wrap>()?.spacing ?? 0;
    return LayoutBuilder(
      builder: (context, constraints) => SizedBox(
        width: ((constraints.maxWidth - spacing * (cols - 1)) / cols)
            .truncateToDouble(),
        child: child,
      ),
    );
  }
}
